package jsqlparser;

import java.io.StringReader;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;

import org.junit.Test;

public class FirstTest {

	@Test
	public void test() throws JSQLParserException {
		
		long start = System.currentTimeMillis();
		for(int i = 0; i < 10000; i++){
			
			CCJSqlParserManager parser = new CCJSqlParserManager();
			StringReader reader = new StringReader("select * from student,teacher"
					+ " where age=123 and name='asdfadf'"
					+ " group by a,c"
					+ " having a=23"
					+ " order by b,c");
			Statement state =parser.parse(reader);
			if(state instanceof Select){
				
				Select select = (Select)state;
				PlainSelect plainSelect = (PlainSelect)select.getSelectBody();
				System.out.println(plainSelect.getSelectItems());
				System.out.println(plainSelect.getFromItem());
				System.out.println(plainSelect.getJoins());
				System.out.println(plainSelect.getWhere());
				System.out.println(plainSelect.getGroupByColumnReferences());
				System.out.println(plainSelect.getHaving());
				System.out.println(plainSelect.getOrderByElements());
			}
		}
		long end = System.currentTimeMillis();
		System.out.println("花费时间：" + ((end-start)/1000) + "秒");
	}

}
